package com.example.model_user.login

import com.chendechao.lib_base.BaseRepository
import com.example.model_user.api.UserApiService
import javax.inject.Inject

class LoginRepository @Inject constructor() :BaseRepository(){
    //11, 注入网络请求接口
    @Inject
    lateinit var userApiService: UserApiService

    //9, 发送真是的网络请求
    suspend fun login(username:String,password:String):Result<LoginUiState>{
        //10, 调用网络请求Retrofit+okhttp
        val userInfo = userApiService.getUserInfo(username,password)
        return if(userInfo.code == 200){
            // 16, 返回数据
            Result.success(LoginUiState(userInfo = userInfo.data, isSucess = true))
        }else{
            Result.failure(IllegalArgumentException("用户名或密码错误"))
        }
    }
}